package com.lch.designpattern.combination;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: liuchenhui
 * @create: 2020-03-08 15:36
 **/
public class ChildMenu extends Root {

    private List<Root> list = new ArrayList<>();

    public int level;

    public ChildMenu(String name, int level) {
        super(name);
        this.level = level;
    }

    @Override
    public void show() {
        if (this.list.size() != 0 && this.level != 1) {
            System.out.print("+");
        }
        System.out.println(this.name);
        for (Root root : list) {
            if (this.level != 0) {
                for (int i = 0; i < this.level; i++) {
                    System.out.print(" ");
                }
            }
            root.show();
        }
    }

    public void adChild(Root root) {
        list.add(root);
    }
}
